package com.digitalgeko.hourreporter.fragments;

import com.digitalgeko.hourreporter.*;

import android.app.*;
import android.content.*;
import android.os.*;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.*;

import java.util.*;

public class MenuFragment extends ListFragment {

	public static List<Activity> actividadesLevantadas = new ArrayList<Activity>();
	public static Activity actual, menu;
	public static int menuPosition;
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		setListAdapter(new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, new String[] { " Hours", " Proyects", " Reports", " Salir"}));
		getListView().setCacheColorHint(0);
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		if(menuPosition != position){
			switch(position){
			case 0:
				startActivity(new Intent().setComponent(new ComponentName(actual, InsertReportActivity.class)));
				break;
			case 1:
				startActivity(new Intent().setComponent(new ComponentName(actual, ProyectTaskActivity.class)));
				break;
			case 2:
				break;
			case 3:
				close();
				for(Activity temp : actividadesLevantadas){
					temp.finish();
				}
				break;
			}
		}
		close();
	}
	
	private void close(){
		switch(menuPosition){
		case 0:
			((InsertReportActivity)getActivity()).closeSlideoutHelper();
			break;
		case 1:
			((ProyectTaskActivity)getActivity()).closeSlideoutHelper();
			break;
		case 2:
			break;
		}
	}
	
}